	$(document).ready(function(){
		 //弹窗提前加载以免影响性能
		 //		权限判断
		 $('.dw_name').text($.cookie('Name'));
		 $('.dw_part').text($.cookie('Department'));
		if($.cookie('ID') == null){
			window.location.href="http://www.duoweish.com/crm/login.html";
		}
//		2，3号权限
		if($.cookie('Right') == 1){
			window.location.href="http://www.duoweish.com/crm/index.html";
		}
		
	     
		 $.ajax({
			
  				type:"get",
  				data:{
  						UserId:$.cookie('ID')
  					},
  				url:"http://www.duoweish.com/apis/Dwmain/",
  				success:function(data){
  					Form(data[4],data[5])
  					$('.sale_num').text(data[0]);
  					$('.refund_num').text(data[1]);
  					$('.event_num').text(data[2]);
  					$('.talk_num').text(data[3]);
  					$('.input_form1').val(data[6][0]);
  					$('.input_form2').val(data[6][1]);
  					$('.input_form3').val(data[6][2]);
  					important_set(data[7]);
  				   }
  				   
  			
			})
		///统计图表初始化
		$('.new_event').click(function(){
			layer.open({
									        type: 2
									        ,anim:1
									        ,title: '新建事件'
									        ,closeBtn: 1
									        ,shade: 0.5
									        ,shadeClose:true
									        ,area:['600px','650px']
									        ,id:'my_open'
									        ,scrollbar:false
									        ,btnAlign: 'c'
									        ,moveType: 1 
									        ,content:'http://www.duoweish.com/crm/new_event.html'
										    ,success: function(index){
										    	
										    	
										    	
										    	     
							          	}
							    	 })
		})
		$('.new_talk').click(function(){
			console.log()
			 layer.open({
								        type: 2
								        ,title: false
								        ,closeBtn: 1
								        ,area:['1360px','90%']
								        ,shadeClose:true
								        ,shade: 0.8
								        ,id: 'LAY_layuipro' 
								       ,anim:1
								        ,btnAlign: 'c'
								        ,moveType: 1 
								        ,content:'http://www.duoweish.com/crm/new_talk.html'
									    ,success: function(){
									    	
						          	}
						    	 })
		})
		function Form(formData1,formData2){
			
				new Morris.Line({
			        element: 'grade_chart',
			        data: formData1,
			        xkey: 'day',
			        ykeys: ['value1','value2'],
			        labels: ['销售','退款'],
			        parseTime:false　　

		    })
				new Morris.Line({
			        element: 'work_chart',
			        data: formData2,
			 		lineColors:['white','white'],
			 		lineWidth:'1px',
			 		gridTextColor:"white",
			 		goalLineColors:'white',
			        xkey: 'day',
			        ykeys: ['value1','value2','value3'],
			        labels: ['沟通','事件','销售'],
			        parseTime:false　　
			    });
		      }
		
		 function important_set(data){
		 	for (var i = 0;i<data.length;i++) {
		 		var Text = ` <div class="item">
                         <img src="img/avatar2.jpg" alt="user image" class="online">

                         <p class="message">
                           <a href="#" class="name">
                           <small class="text-muted pull-right"><i class="fa fa-clock-o"></i> ${data[i][2]}</small>
                            ${data[i][0]}
                          </a>
                            ${data[i][1]}
                         </p>
             		 </div>` ;
             	$('.import_item').append(Text);
		 	}
		 	
		 }
	})